package com.health.mapp.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.health.db.model.SubRegisterOrder;
import com.health.db.model.SubRegisterOrderExample;
import com.health.db.service.order.ISubRegisterOrderService;
import com.health.mapp.bean.Header;
import com.health.mapp.bean.QuerySubOrderReq;
import com.health.mapp.bean.QuerySubOrderResp;
import com.health.mapp.utils.Response;
import com.health.mapp.utils.ResultCode;

/**
 *  子订单查询类
 * @author YuChong
 *
 */
public class QuerySubOrderImpl implements ActionInterface {

	 private  ISubRegisterOrderService subRegisterOrderService;
	
	@Override
	public Response execute(Header header, Object reqBean) throws Exception {
		
		QuerySubOrderReq req=(QuerySubOrderReq) reqBean;
		QuerySubOrderResp _resp= new QuerySubOrderResp();
		
		SubRegisterOrderExample temp = new SubRegisterOrderExample();
		
		Integer pageNo=req.getPageNo();
		Integer pageSize=req.getPageNum();
		
		if(null!=pageNo&&null!=pageSize){
			temp.setOffset((pageNo.intValue()-1)*pageSize.intValue());
			temp.setPageSize(pageSize.intValue());
		}
		//预订单Id
		 String orderId =req.getOrderId();
		 String subOrderId=req.getSubOrderId();
		//用户编号
		 String userId = req.getUserId();
		 String docId =  req.getDocId();
		 String orderState = req.getOrderState();
		
		 //医生编号 用户编号 订单号 取一
		 if(StringUtils.isNotBlank(subOrderId)){
			temp.setSubOrderId(Long.valueOf(req.getOrderId()));
		}else if(StringUtils.isNotBlank(orderId)){
			temp.setOrderId(Long.valueOf(orderId));
		}else if(StringUtils.isNotBlank(userId)){
			temp.setUserId(Long.valueOf(userId));
		}else if(StringUtils.isNotBlank(docId)){
			temp.setAccepterid(Long.valueOf(docId));
		}else {
			_resp.setErrorCode(ResultCode.OPERATION_LAKE_PARAMETER_ERROR);
			_resp.setErrorMsg(ResultCode.OPERATION_LAKE_PARAMETER_ERROR_NOTE);
			return _resp;
		}
		if (StringUtils.isNotBlank(orderState)) {
			temp.setRunstatusid(Integer.valueOf(orderState));
		}
	
		List<SubRegisterOrder> orderList = subRegisterOrderService.selectSimple(temp);
		
		_resp.setSubOrderInfoList(orderList);
		_resp.setPageNo(pageNo);
		_resp.setPageNum(pageSize);
		_resp.setErrorCode(ResultCode.OPERATION_SUCCESS);
		_resp.setErrorMsg(ResultCode.OPERATION_SUCCESS_NOTE);
 
		return _resp;
	}

	public ISubRegisterOrderService getSubRegisterOrderService() {
		return subRegisterOrderService;
	}

	public void setSubRegisterOrderService(
			ISubRegisterOrderService subRegisterOrderService) {
		this.subRegisterOrderService = subRegisterOrderService;
	}
}
